package com.future.mvc.web.interceptor;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <P>
 * 自定义拦截器01
 * </p>
 *
 * @author yinhao
 * @version 1.0
 * @since 2024/9/8 16:39
 */
@Component
public class FutureInterceptor02 implements HandlerInterceptor {

    /**
     * 1. 在目标方法执行前被执行;
     * 2. 如果返回false, 不再执行目标方法;
     * 3. 根据业务拦截, 可以指定跳转到哪个页面.
     */
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("FutureInterceptor02-preHandle()--");
        return false;
    }

    /**
     * 1. 在目标方法执行后执行;
     * 2. 该方法可以获取到目标方法返回的modelAndView,做二次处理
     */
    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        System.out.println("FutureInterceptor02-postHandle()--");
    }

    /**
     * 1. 该方法在整个请求完成之后被调用, 也就是说在视图渲染之后;
     */
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        System.out.println("FutureInterceptor02-afterCompletion()--");
    }
}
